package com.bocloud.service.tool;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bocloud.dto.LoginInfoDto;
import com.bocloud.dto.PickDto;
import com.bocloud.enumeration.InterfaceStatus;
import com.bocloud.enumeration.MonitorType;
import com.bocloud.enumeration.RequestMethod;
import com.bocloud.enumeration.TrueOrFalse;
import com.bocloud.framework.MyException;
import com.bocloud.inter.service.table.IErrorService;
import com.bocloud.inter.service.table.IMenuService;
import com.bocloud.inter.service.tool.IPickService;
import com.bocloud.model.Error;
import com.bocloud.utils.Tools;

/**
 * 下拉选着
 * 
 * @author Ehsan
 *
 */
@Service("pickService")
public class PickService implements IPickService {
	@Autowired
	IMenuService menuService;
	@Autowired
	private IErrorService errorService;

	@Override
	public void getPickList(List<PickDto> picks, String code, String key, LoginInfoDto user) throws MyException {
		PickDto pick = null;
		switch (code) {
		case "REQUESTMETHOD": // 枚举 请求方式 post get
			for (RequestMethod status : RequestMethod.values()) {
				pick = new PickDto(status.name(), status.getName(), status.getName());
				picks.add(pick);
			}
			return;
		// 枚举 接口状态
		case "INTERFACESTATUS":
			for (InterfaceStatus status : InterfaceStatus.values()) {
				pick = new PickDto(status.getName(), status.name());
				picks.add(pick);
			}
			return;
		case "TRUEORFALSE":// 枚举true or false
			for (TrueOrFalse status : TrueOrFalse.values()) {
				pick = new PickDto(status.getName(), status.name());
				picks.add(pick);
			}
			return;
		case "MONITORTYPE":// 监控类型
			for (MonitorType monitorType : MonitorType.values()) {
				pick = new PickDto(monitorType.name(), monitorType.getValue() + "", monitorType.getName());
				picks.add(pick);
			}
			return;
		case "ERRORCODE":// 错误码
			for (Error error : errorService.findByMap(Tools.getMap("moduleId", key), null, "errorCode asc")) {
				pick = new PickDto(error.getErrorCode(), error.getErrorCode() + "--" + error.getErrorMsg());
				picks.add(pick);
			}
			return;
		}
	}

}
